﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using IDAL.RF.Package;
using Model.RF.Package;

namespace DAL.RF.Package
{
    public class SNUnion : BaseRepository_DT<SNUnionInfo>, ISNUnion
    {
        #region 静态变量部分
        private const string PARM_PACKAGEPRODUCTSN = "@PackageProductSN";
        private const string PARM_PRODUCTSN = "@ProductSN";
        private const string PARM_PRODUCTTYPEID = "@ProductTypeID";
        private const string PARM_RECORDTIME = "@RecordTime";
        private const string PARM_USERID = "@UserID";
        #endregion

        #region 数据检索部分
        public IList<SNUnionInfo> LoadEntities()
        {
            return null;
        }

        /// <summary>
        /// SNUnion_GetbyProductSN
        /// </summary>
        public SNUnionInfo LoadEntity<T1>(T1 productSN)
        {
            SqlParameter parm = GetParameter();
            parm.Value = productSN;
            return ExcuteSqlToGetEntity("SNUnion_selectbyProductSN", parm);
        }

        public IList<SNUnionInfo> SNUnion_GetbyPackageProductSN(string packageProductSN)
        {
            SqlParameter parm = new SqlParameter(PARM_PACKAGEPRODUCTSN, SqlDbType.NVarChar, 100);
            parm.Value = packageProductSN;
            return ExcuteSqlToGetEntities("SNUnion_selectbyPackageProductSN", parm);
        }

        public IList<SNUnionInfo> SNUnion_GetbyDT(DateTime starttime, DateTime stoptime)
        {
            SqlParameter[] parms = GetDTParameters();
            parms[0].Value = starttime;
            parms[1].Value = stoptime;
            return ExcuteSqlToGetEntities("SNUnion_selectbyDT", parms);
        }
        #endregion


        #region 重写基类部分
        //-------------------------------------重写超类基础操作---------------------------------------------------------

        public override SNUnionInfo GetEntityRecord(SqlDataReader rdr)
        {
            SNUnionInfo pro = new SNUnionInfo()
            {
                PackageProductSN = rdr.GetValue(0).ToString(),
                ProductSN = rdr.GetValue(1).ToString(),
                ProductTypeID = rdr.GetValue(2).ToString(),
                RecordTime = rdr.GetDateTime(3),
                UserID = rdr.GetValue(4).ToString()
            };
            return pro;
        }

        public override SNUnionInfo GetEntityRecord()
        {
            SNUnionInfo pro = new SNUnionInfo();
            return pro;
        }

        public override string GetInsertsp()
        {
            return "SNUnion_Insert";
        }

        public override string GetUpdatesp()
        {
            return null;
        }

        public override string GetDeletesp()
        {
            return null;
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter Parm = new SqlParameter(PARM_PRODUCTSN, SqlDbType.NVarChar,50);
            return Parm;
        }

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
                    new SqlParameter(PARM_PACKAGEPRODUCTSN, SqlDbType.NVarChar, 100),
					new SqlParameter(PARM_PRODUCTSN, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_PRODUCTTYPEID, SqlDbType.NVarChar,50),
                    new SqlParameter(PARM_RECORDTIME, SqlDbType.DateTime, 8),
                    new SqlParameter(PARM_USERID, SqlDbType.NVarChar, 20),
                };
            return parms;
        }

        public override void SetParameters(SNUnionInfo entity, params SqlParameter[] Parms)
        {
            Parms[0].Value = entity.PackageProductSN;
            Parms[1].Value = entity.ProductSN;
            Parms[2].Value = entity.ProductTypeID;
            Parms[3].Value = entity.RecordTime;
            Parms[4].Value = entity.UserID;
        }
        #endregion
    }
}
